package com.ruoyi.xiaoshou.service.impl;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.xiaoshou.domain.SalesmanReport;
import com.ruoyi.xiaoshou.mapper.SalesmanReportMapper;
import com.ruoyi.xiaoshou.service.ISalesmanReportService;
import com.ruoyi.xiaoshou.utils.JasperPdfUtil;
import net.sf.jasperreports.engine.JRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 销售业务员报表Service业务层处理
 *
 * @author wl
 * @date 2024-11-08
 */
@Service
public class SalesmanReportServiceImpl implements ISalesmanReportService {
    @Autowired
    private SalesmanReportMapper salesmanReportMapper;

    /**
     * 查询销售业务员报表列表
     *
     * @param salesmanReport 销售业务员报表
     * @return 销售业务员报表
     */
    @Override
    public List<SalesmanReport> selectSalesmanReportList(SalesmanReport salesmanReport) {
        return salesmanReportMapper.selectSalesmanReportList(salesmanReport);
    }

    /**
     * @return byte[]
     * @description 导出销售员报表pdf
     * @date 2024/11/15 下午5:19
     * @Param salesmanReport:
     **/
    public byte[] printSalesmanReport(SalesmanReport salesmanReport) throws JRException, FileNotFoundException {
        String templatePath = "jasper/SalemanReport.jrxml";
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("createBy", SecurityUtils.getUsername());
        List<SalesmanReport> list = salesmanReportMapper.selectSalesmanReportList(salesmanReport);
        return JasperPdfUtil.exportPdfFromXml(templatePath, paramsMap, list);
    }
}
